package com.vay.de.dang.online.view;

import android.content.Context;
import android.graphics.Color;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.vay.de.dang.online.R;

public class VnTabButton extends FrameLayout {

    private ImageView tabIcon;
    private TextView tabLabel;
    private int preResId;
    private int norResId;

    public VnTabButton(@NonNull Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        View iv = LayoutInflater.from(context).inflate(R.layout.tab_view, null);
        addView(iv, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
        tabIcon = iv.findViewById(R.id.tab_icon);
        tabLabel = iv.findViewById(R.id.tab_tv);
    }

    public VnTabButton loadTab(int resNId, int resPId, String label) {
        norResId = resNId;
        preResId = resPId;
        tabIcon.setImageResource(resNId);
        tabLabel.setText(label);
        return this;
    }

    public void switchTab(boolean selected) {
        if (selected) {
            tabIcon.setImageResource(preResId);
            tabLabel.setTextColor(Color.parseColor("#333333"));
        } else {
            tabIcon.setImageResource(norResId);
            tabLabel.setTextColor(Color.parseColor("#88999999"));
        }
    }
}
